<?php
namespace app\admin\model;
class Jc extends BaseModel{
    
    
    function getAllMoney($res){
        $qidetail = D('qideatils');
        //1：小，2：大，3：小双，4：小单，5：大单，6：大双，8：精准，9：合
        $data["small"] = $qidetail->where("xiazhu_type",1)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["big"] = $qidetail->where("xiazhu_type",2)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["smallDouble"] = $qidetail->where("xiazhu_type",3)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["smallSingle"] = $qidetail->where("xiazhu_type",4)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["bigSingle"] = $qidetail->where("xiazhu_type",5)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["bigDouble"] = $qidetail->where("xiazhu_type",6)->where("qi_id",$res['id'])->sum("money * peilv /100");
        
        $data["he"] = $qidetail->where("xiazhu_type",9)->where("qi_id",$res['id'])->sum("money * peilv /100");
        $data["total"] = $qidetail->where("qi_id",$res['id'])->sum("money");
        foreach ($data as &$tmp){
            if ($tmp==null){
                $tmp=0;
            }
        }
        unset($tmp);
        $jzarr = [];
        for ($i=0;$i<10;$i++){
            $jzarrTmp['money'] = $qidetail->where("xiazhu_type",8)->where("num","".$i)->where("qi_id",$res['id'])->sum("money * peilv /100");
            if(!$jzarrTmp['money']){
                $jzarrTmp['money']=0;
            }
            $jzarrTmp['num'] = $i;
            array_push($jzarr, $jzarrTmp);
        }
        $data['jz'] = $jzarr;
        
        return $data;
    }
    
    function getAllMoney2($res){
        $qidetail = D('qideatils');
        //1：小，2：大，3：小双，4：小单，5：大单，6：大双，8：精准，9：合
        $data["small"] = $qidetail->where("xiazhu_type",1)->where("qi_id",$res['id'])->sum("money/100");
        $data["big"] = $qidetail->where("xiazhu_type",2)->where("qi_id",$res['id'])->sum("money/100");
        $data["smallDouble"] = $qidetail->where("xiazhu_type",3)->where("qi_id",$res['id'])->sum("money/100");
        $data["smallSingle"] = $qidetail->where("xiazhu_type",4)->where("qi_id",$res['id'])->sum("money/100");
        $data["bigSingle"] = $qidetail->where("xiazhu_type",5)->where("qi_id",$res['id'])->sum("money/100");
        $data["bigDouble"] = $qidetail->where("xiazhu_type",6)->where("qi_id",$res['id'])->sum("money/100");
    
        $data["he"] = $qidetail->where("xiazhu_type",9)->where("qi_id",$res['id'])->sum("money/100");
        $data["total"] = $qidetail->where("qi_id",$res['id'])->sum("money/100");
        foreach ($data as &$tmp){
            if ($tmp==null){
                $tmp=0;
            }
        }
        unset($tmp);
        $jzarr = [];
        for ($i=0;$i<10;$i++){
            $jzarrTmp['money'] = $qidetail->where("xiazhu_type",8)->where("num","".$i)->where("qi_id",$res['id'])->sum("money/100");
            if(!$jzarrTmp['money']){
                $jzarrTmp['money']=0;
            }
            $jzarrTmp['num'] = $i;
            array_push($jzarr, $jzarrTmp);
        }
        $data['jz'] = $jzarr;
    
        return $data;
    }
    
    
    function countsyingli($str) {
        $aaaa = [];
        $jccount = new \app\index\model\Jccount();
        $res = $jccount->getLock();
        $first = intval(str_get_last($str, 3));
        $second = intval(str_get_last($str, 2));
        $last = intval(str_get_last($str, 1));
        $data = $this->getAllMoney($res);
        $aaaa['total']=$data['total'];
    if ($last==$second){
            //合
            $aaaa['yingli']=$data['total'] - $data['he'];
            return $aaaa;
        }else {
            //不是合
            $z = 0;
            if ($last<5){
                $z+=$data['small'];
            }else {
                $z+=$data['big'];
            }
            $tmp = $first+$second+$last;
            if ($tmp<14){
                if ($tmp%2==0){
                    
                $z+=$data['smallDouble'];
                }else {
                    
                $z+=$data['smallSingle'];
                }
            }else {
                if ($tmp%2==0){
                    
                $z+=$data['bigDouble'];
                }else {
                    
                $z+=$data['bigSingle'];
                }
            }
            $qidetail = D('qideatils');
            $jzmoney = $qidetail->where("xiazhu_type",8)->where("num","".$last)->where("qi_id",$res['id'])->sum("money * peilv /100");
            if (!$jzmoney){
                $jzmoney=0;
            }
            $z+=$jzmoney;
            $aaaa['yingli']=$data['total'] - $z;
            return $aaaa;
        }
    }
    function rand6(){
        $res = "";
        for ($i=0;$i<6;$i++){
            if($i==0){
                $res=$res.rand(1, 9);
            }else{
                $res=$res.rand(0, 9);
            }
    
        }
        return $res;
    }
}

